package com.bawei.module_service.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_service.R
import com.bawei.module_service.adapter.MaintainAdapter.MaintainViewHolder
import com.bawei.module_service.databinding.ItemPatrolBinding
import com.bawei.module_service.databinding.MaintainitemBinding
import com.bawei.module_service.databinding.ServiceitemBinding
import com.bawei.module_service.model.MaintainModelItem
import com.bawei.module_service.model.PatrolModelItem
import com.bawei.module_service.model.ServiceItemModel

class PatrolAdapter : RecyclerView.Adapter<PatrolAdapter.PatrolViewHolder>() {

    private val list= mutableListOf<PatrolModelItem>()
    fun setData(data:List<PatrolModelItem>){
        list.clear()
        list.addAll(data)
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): PatrolAdapter.PatrolViewHolder {
        val binding= ItemPatrolBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return PatrolViewHolder(binding)
    }

    override fun onBindViewHolder(holder: PatrolViewHolder, position: Int) {
        val binding= DataBindingUtil.getBinding<ItemPatrolBinding>(holder.itemView)
        binding?.name?.setText(list[position].patrolPerson)
        binding?.zw?.setText(list[position].taskName)
        binding?.time?.setText(list[position].patrolTime)
        if(list[position].patrolStatus.equals("0")){
            binding?.jxz?.setText("待开始")
            binding?.jxz?.setBackgroundResource(R.drawable.bg_no)
        }else if(list[position].patrolStatus.equals("1")){
            binding?.jxz?.setText("进行中")
            binding?.jxz?.setBackgroundResource(R.drawable.bg_do)
        }else{
            binding?.jxz?.setText("已完成")
            binding?.jxz?.setBackgroundResource(R.drawable.bg_ok)

        }
    }

    override fun getItemCount(): Int {
        return list.size
    }
    class PatrolViewHolder(val binding: ItemPatrolBinding):RecyclerView.ViewHolder(binding.root)
}